package cn.itcast.fangkuai;


import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

public class Client extends JFrame implements ActionListener {

	static JMenu game = new JMenu("游戏");
	JMenuItem newGame = game.add("新游戏");
	JMenuItem pauseGame = game.add("暂停");
	JMenuItem continueGame = game.add("继续");
	JMenuItem exitGame = game.add("退出");
	static JMenu help = new JMenu("帮助");
	JMenuItem about = help.add("关于");
	GamePanel panel = new GamePanel();

	static {

	}

	public Client() {
		addKeyListener(panel);// 为游戏面板添加监听
		this.getContentPane().add(panel);
		newGame.addActionListener(this);
		pauseGame.addActionListener(this);
		continueGame.addActionListener(this);
		exitGame.addActionListener(this);
		about.addActionListener(this);
		JMenuBar menu = new JMenuBar();
		setJMenuBar(menu);
		menu.add(game);
		menu.add(help);
		setLocationRelativeTo(null);// 让窗口显示在屏幕正中间
		setTitle("俄罗斯方块");
		setSize(340, 395);
		//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 当用户点击窗体右上角x时自动退出程序
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);// 当用户点击窗体右上角x时自动退出程序
		setResizable(false);
		setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == newGame) {
			panel.newGame();
		} else if (e.getSource() == pauseGame) {
			panel.pauseGame();
		} else if (e.getSource() == continueGame) {
			panel.continueGame();
		} else if (e.getSource() == exitGame) {
            this.dispose();
		} else if (e.getSource() == about) {
			displayToast("左右键移动，向上键旋转");
		}
	}

	private void displayToast(String string) {
		JOptionPane.showMessageDialog(null, string, "提示",
				JOptionPane.ERROR_MESSAGE);
	}



	/*public static void main(String[] args) {
		new Client();
	}*/



}
